/*
 *  DDSConversion.c
 *  DDSQuickLook
 *
 *  Created by Torsten Kammer on 18.02.08.
 *  Copyright 2008 Ferroequinologist.de. All rights reserved.
 *
 */

#include "DDSConversion.h"
#include "WriteDDSFile.h"

Boolean DDSConvertFrom(CFURLRef originalFile, CFURLRef outFile, CFStringRef outFileUTI)
{
    DDSFile *file = DDSOpenFile(originalFile);
    if (!file) return false;
    
    CFIndex fileWidth = DDSGetWidth(file);
	CFIndex fileHeight = DDSGetHeight(file);
	
	CGImageRef image = DDSCreateImage(file, fileWidth, fileHeight);
    DDSDestroy(file);
    if (!image) return false;
    
    CGImageDestination *destination = CGImageDestinationCreateWithURL(outFile, outFileUTI, 1, NULL);
    if (!destination)
    {
        CGImageRelease(image);
        return false;
    }
    CGImageDestinationAddImage(destination, image, NULL);
    CGImageDestinationFinalize(destination);
    CFRelease(destination);
    
    CGImageRelease(image);
    
    return true;
}
